# -*- coding: utf-8 -*-
import xlrd
import xlwt
import re
import requests
import json
import time
workbook = xlrd.open_workbook('count.xlsx')

sheet_names = workbook.sheet_names()

# sheet = workbook.sheet_by_name('工作表1')
sheet = workbook.sheet_by_index(0)


numb = 0
money = 1328
# 循环Excel文件的所有行
for row in sheet.get_rows():
    numb += 1
    if numb < 12 or numb>33:
        continue
    if len(re.findall('jd.com',row[4].value)) < 1:
        continue

    # 循环一行的所有列

    # print('商品', numb, ':', row[0].value)
    # print('参考价格：', row[2].value)
    # print('数量:', row[3].value)


    #url = 'https://item.jd.com/435168.html'
    url = row[4].value
    m = re.search('\d+', url)


    urlnew = 'http://p.3.cn/prices/gets?skuid=J_'+str(m.group(0))

    price = requests.get(urlnew)
    newprice = price.content.decode('utf-8')

    newprice = json.loads(newprice)
    newprice = float(newprice[0]['p'])
    srcprice = float(row[2].value)

   # print('最新价格：',newprice[0]['p'])


    if (srcprice - newprice) > 0 :
        print('【降价了】',row[0].value )
        print('原价：',str(srcprice),'现价：',str(newprice),'降了：',str(srcprice-newprice),'元')
        #金额
        mo = float(row[3].value) * (srcprice - newprice)

        print('数量：',row[3].value,'金额：',str(mo))

        money = money + mo




    time.sleep(1)

print(money)